<template>
    <div class="borrow-header">
        <!--html结构在此书写-->
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="用户名">
                <el-input v-model="formInline.user" placeholder="请输入用户名" clearable />
            </el-form-item>
            <el-form-item label="借阅状态">
                <el-select v-model="formInline.region" placeholder="全部" clearable>
                    <el-option label="借阅中" value="借阅中" />
                    <el-option label="已归还" value="已归还" />
                    <el-option label="已逾期" value="已逾期" />
                    <el-option label="全部" value="全部" />
                </el-select>
            </el-form-item>
            <el-form-item label="借阅时间">
                <el-date-picker v-model="formInline.date" type="date" placeholder="请选择日期" clearable />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">搜索</el-button>
                <el-button type="primary" @click="onSubmit">添加</el-button>
            </el-form-item>
        </el-form>
    </div>

    <div class="borrow-table">
        <el-table :data="tableData" style="width: 100%">
            <el-table-column fixed prop="userId" label="用户id" width="150" />
            <el-table-column prop="name" label="用户名" width="120" />
            <el-table-column prop="bookName" label="书名" width="120" />
            <el-table-column prop="borrowDate" label="借阅日期" width="120" />
            <el-table-column prop="returnDate" label="归还日期" width="100" />
            <el-table-column prop="status" label="状态" width="120">
                <template #default="item">

                    <el-tag v-if="item.row.status === 0" type="danger">不可用</el-tag>
                    <el-tag v-else-if="item.row.status === 1" type="primary">借阅中</el-tag>
                    <el-tag v-else-if="item.row.status === 2" type="success">已归还</el-tag>
                    <el-tag v-else-if="item.row.status === 3" type="warning">已逾期</el-tag>

                </template>
            </el-table-column>

            <el-table-column fixed="right" label="操作" min-width="120">
                <template #default>
                    <el-button link type="primary" size="small" @click="handleClick">
                        编辑
                    </el-button>
                    <el-button link type="danger" size="small">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>

    <div class="borrow-view-footer">
        <el-pagination size="small" background layout="prev, pager, next" :total="50" class="mt-4" />
    </div>
</template>

<script setup lang="ts">
// 引入组件
// import Xxx from '...'
import { reactive } from 'vue'

const formInline = reactive({
    user: '',
    region: '',
    date: '',
})

const onSubmit = () => {
    console.log('submit!')
}



const handleClick = () => {
    console.log('click')
}

const tableData = [
    {
        userId: 1,
        name: '张三',
        bookName: '《算法导论》',
        borrowDate: '2022-01-01',
        returnDate: '2022-01-01',
        status: 0
    },
    {
        userId: 2,
        name: '李四',
        bookName: '《算法导论》',
        borrowDate: '2022-01-01',
        returnDate: '2022-01-01',
        status: 1
    },
    {
        userId: 3,
        name: '王五',
        bookName: '《算法导论》',
        borrowDate: '2022-01-01',
        returnDate: '2022-01-01',
        status: 2
    },
    {
        userId: 4,
        name: '赵六',
        bookName: '《算法导论》',
        borrowDate: '2022-01-01',
        returnDate: '2022-01-01',
        status: 3
    },
    {
        userId: 5,
        name: '钱七',
        bookName: '《算法导论》',
        borrowDate: '2022-01-01',
        returnDate: '2022-01-01',
        status: 1
    }
]

</script>

<style scoped>
/* 样式内容 */
.demo-form-inline .el-input {
    --el-input-width: 220px;
}

.demo-form-inline .el-select {
    --el-select-width: 220px;
}
</style>